package com.ruoyi.web.controller.talentServerController;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TalNoticePayment;
import com.ruoyi.system.service.ITalNoticePaymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党费催缴Controller
 *
 * @author anxinm
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/payment")
public class TalNoticePaymentController extends BaseController
{
    @Autowired
    private ITalNoticePaymentService talNoticePaymentService;

    /**
     * 查询党费催缴列表
     */
    @PreAuthorize("@ss.hasPermi('system:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TalNoticePayment talNoticePayment)
    {
        startPage();
        List<TalNoticePayment> list = talNoticePaymentService.selectTalNoticePaymentList(talNoticePayment);
        for (TalNoticePayment payment : list) {
            payment.setNoticeDescribe(payment.getIsNotice() == 0L ? "未催缴" : "已催缴");
            payment.setPaymentDescribe(payment.getIsPayment() == 0L ? "未缴纳" : "已缴纳");
        }
        return getDataTable(list);
    }

    /**
     * 导出党费催缴列表
     */
    @PreAuthorize("@ss.hasPermi('system:payment:export')")
    @Log(title = "党费催缴", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TalNoticePayment talNoticePayment)
    {
        List<TalNoticePayment> list = talNoticePaymentService.selectTalNoticePaymentList(talNoticePayment);
        ExcelUtil<TalNoticePayment> util = new ExcelUtil<TalNoticePayment>(TalNoticePayment.class);
        util.exportExcel(response, list, "党费催缴数据");
    }

    /**
     * 获取党费催缴详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:payment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(talNoticePaymentService.selectTalNoticePaymentById(id));
    }

    /**
     * 新增党费催缴
     */
    @PreAuthorize("@ss.hasPermi('system:payment:add')")
    @Log(title = "党费催缴", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TalNoticePayment talNoticePayment)
    {
        return toAjax(talNoticePaymentService.insertTalNoticePayment(talNoticePayment));
    }

    /**
     * 修改党费催缴
     */
    @PreAuthorize("@ss.hasPermi('system:payment:edit')")
    @Log(title = "党费催缴", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TalNoticePayment talNoticePayment)
    {
        return toAjax(talNoticePaymentService.updateTalNoticePayment(talNoticePayment));
    }

    /**
     * 删除党费催缴
     */
    @PreAuthorize("@ss.hasPermi('system:payment:remove')")
    @Log(title = "党费催缴", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(talNoticePaymentService.deleteTalNoticePaymentByIds(ids));
    }

    @PostMapping("/updateState")
    public AjaxResult updateState(@RequestBody TalNoticePayment payment)
    {
        talNoticePaymentService.updateState(payment) ;
        return success();
    }
}
